﻿function ClientSyncDepartmentWithPlugInService() {
    document.getElementById("divProcessing").innerHTML = Portal.SystemWebParts.Department.Department.GetProcessingText().value;
    setTimeout("RealSyncDepartmentWithPlugInService()", 10);
}

function RealSyncDepartmentWithPlugInService() {
    retValue = Portal.SystemWebParts.Department.Department.ServerSideSyncDepartmentWithPlugInService().value;
    document.getElementById("divProcessing").innerHTML = "";
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}

function RunFilter()
{
    document.getElementById("divProcessing").innerHTML=Portal.SystemWebParts.Department.Department.GetProcessingText().value;
    setTimeout("RealRunFilter()",10);
}

function RealRunFilter()
{
    PageIndex=0;
    if(document.getElementById("divSelectPage")!=null)
    {
        PageIndex=document.getElementById("divSelectPage").selectedIndex;
    }
    value=Portal.SystemWebParts.Department.Department.GetDepartment(PageIndex).value;
    if(value.indexOf("ERROR")!=-1)
    {
        alert(value);
        return;
    }
    document.getElementById("divProcessing").innerHTML="";
    document.getElementById("divDepartmentContent").innerHTML=value;
}


function DeleteDepartment(DepartmentId)
{
    ConfirmMsg=Portal.SystemWebParts.Department.Department.GetConfirmDeleteMsg().value;
    if(confirm(ConfirmMsg)==false)return;
    retValue = Portal.SystemWebParts.Department.Department.ServerSideDeleteDepartment(DepartmentId).value;
    Portal.SystemWebParts.Department.Department.ServerSideMakeXml().value;
    alert(retValue);
    if(retValue.indexOf("ERROR")!=-1)
    {
        RunFilter();
    }
}


function ClientAddDepartment() {
    Url = Portal.SystemWebParts.Department.Department.GetAddDepartmentUrl().value;
    window.open(Url, '_blank');
}



function ClientSaveAddDepartment(OfficeId) {
    DepartmentCode = document.getElementById("txtDepartmentCode").value;
    DepartmentName = document.getElementById("txtDepartmentName").value;

    retValue = Portal.SystemWebParts.Department.AddDepartment.ServerSideAddDepartment(OfficeId, DepartmentCode, DepartmentName).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
   
    window.close();
}

function ShowClientUpdateUrlForm(DepartmentId) {
    Url = Portal.SystemWebParts.Department.Department.GetUpdateDepartmentUrl(DepartmentId).value;
    window.open(Url, '_blank');
}


function ClientSaveUpdateDepartment(DepartmentId) {
    DepartmentCode = document.getElementById("txtDepartmentCode").value;
    DepartmentName = document.getElementById("txtDepartmentName").value;
    retValue = Portal.SystemWebParts.Department.UpdateDepartment.ServerSideUpdateDepartment(DepartmentId, DepartmentCode, DepartmentName).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    Portal.SystemWebParts.Department.UpdateDepartment.ServerSideMakeXml().value;
    alert(retValue);
    window.close();
}

function ClientMakeRoleFromDepartment() {
    document.getElementById("divProcessing").innerHTML = Portal.SystemWebParts.Department.Department.GetProcessingText().value;
    setTimeout("RealClientMakeRoleFromDepartment()", 10);
}

function RealClientMakeRoleFromDepartment() {
    retValue = Portal.SystemWebParts.Department.Department.ServerSideCreateRoleFromDepartment().value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
    document.getElementById("divProcessing").innerHTML = "";
}

function ClientMakeXml() {
    document.getElementById("divProcessing").innerHTML = Portal.SystemWebParts.Department.Department.GetProcessingText().value;
    setTimeout("RealClientMakeXml()", 10);
}

function RealClientMakeXml() {
    rValue = Portal.SystemWebParts.Department.Department.ServerSideMakeXml().value;
    document.getElementById("divProcessing").innerHTML = "";
    if (rValue.indexOf("ERROR") != -1) 
    {
        alert(rValue);
        return;
    }
    else 
    {
        alert(rValue);
    }
}